package com.cyjt.operation.adapter;

import java.util.List;

import com.cyjt.operation.R;
import com.cyjt.operation.bean.WorkOrder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

/**
 * 工单管理ListView的Adapter
 * 
 * @author LTP
 *
 */
public class WorkOrderManagementAdapter extends ArrayAdapter<WorkOrder> {
	private int listViewItemResourceId;

	public WorkOrderManagementAdapter(Context context, int resource, List<WorkOrder> objects) {
		super(context, resource, objects);
		// TODO Auto-generated constructor stub
		listViewItemResourceId = resource;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		WorkOrder workOrder = getItem(position);
		View view;
		ViewHolder mViewHolder;
		if (convertView == null) {
			view = LayoutInflater.from(getContext()).inflate(listViewItemResourceId, null);
			mViewHolder = new ViewHolder();
			mViewHolder.textView_work_order_management_id = (TextView) view
					.findViewById(R.id.textView_work_order_management_id);
			mViewHolder.textView_work_order_management_type = (TextView) view
					.findViewById(R.id.textView_work_order_management_type);
			mViewHolder.textView_work_order_management_time = (TextView) view
					.findViewById(R.id.textView_work_order_management_time);
			mViewHolder.textView_work_order_management_deadline = (TextView) view
					.findViewById(R.id.textView_work_order_management_deadline);
			view.setTag(mViewHolder);

		} else {
			view = convertView;
			mViewHolder = (ViewHolder) view.getTag();
		}
		mViewHolder.textView_work_order_management_id.setText(workOrder.getId() + "");
		mViewHolder.textView_work_order_management_type.setText(workOrder.getType() + "");
		mViewHolder.textView_work_order_management_time.setText(workOrder.getTime() + "");
		mViewHolder.textView_work_order_management_deadline.setText(workOrder.getDeadline() + "");
		return view;
	}

	class ViewHolder {
		TextView textView_work_order_management_id;
		TextView textView_work_order_management_type;
		TextView textView_work_order_management_time;
		TextView textView_work_order_management_deadline;
	}
}
